//
//  BBTodayProfitViewController.m
//  BearSiX
//
//  Created by 潘宇 on 16/3/29.
//  Copyright © 2016年 Tom. All rights reserved.
//

#import "BBTodayProfitViewController.h"
#import "BBtp.h"
#import "BBtpCell.h"
#import "BBTodayProfitdetailViewController.h"
@interface BBTodayProfitViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSArray *tpes;

@property(nonatomic,strong)UITableView *tableView;
@end

@implementation BBTodayProfitViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 120;
    
    
}
-(UITableView *)tableView{
    
    if (!_tableView) {
        _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, WINSIZEHEIGHT)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        //_tableView.userInteractionEnabled=NO;
    }
    
    return _tableView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
#pragma mark - tableView数据源方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
      return self.tpes.count;
}
// 返回有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
    
}


// 返回每一行的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 1.创建cell
    BBtpCell *cell = [BBtpCell cellWithTableView:tableView];
    
    // 2.取出模型数据中对应行的模型,传递给自定义cell的
    cell.tp = self.tpes[indexPath.row];
    
    
    
    //    UIImageView *iconView = (UIImageView *)[cell viewWithTag:10];
    //    iconView.image = [UIImage imageNamed:tg.icon];
    
    
    
    
    
    //    cell.textLabel.text = tg.title;
    //    cell.detailTextLabel.text = [NSString stringWithFormat:@"¥:%@                 %@人购买", tg.price, tg.buyCount];
    //    cell.imageView.image = [UIImage imageNamed:tg.icon];
    
    //    NSLog(@"%p--%p---%p--%p--%p",cell, cell.contentView, cell.textLabel.superview, cell.detailTextLabel.superview, cell.imageView.superview );
    
    // 3.返回cell
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    BBTodayProfitdetailViewController* bbtpdVC = [BBTodayProfitdetailViewController new];

    if (indexPath.section>=0) {
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:bbtpdVC animated:YES];
                break;
        }
    }
        
    
}
-(void)goToSet{
    
    [self presentViewController:[BBTodayProfitdetailViewController new] animated:YES completion:nil];
}
#pragma mark - 懒加载
- (NSArray *)tpes {
    if (_tpes == nil) {
        NSArray *dictArr = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]];
        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:dictArr.count];
        for (NSDictionary *dict in dictArr) {
            BBtp *tp = [BBtp tpWithDict:dict];
            [arrM addObject:tp];
        }
        _tpes = arrM;
    }
    return _tpes;
}

@end
